﻿  
 
 IF EXISTS(SELECT NAME FROM SYSOBJECTS WHERE NAME='Proc_RescueAgreement' AND TYPE='P')
BEGIN
  DROP PROCEDURE Proc_RescueAgreement
  PRINT 'Droping Procedure'
END
GO
/* MBB 2010-5-21
救援协议信息分页数据
*/
CREATE Procedure [dbo].[Proc_RescueAgreement] --1,10,'5',''
 	@PageIndex int,
	@PageSize int,
	@EnterpriseName varchar(50),
	@Region varchar(20)
 AS
DECLARE @SQL nvarchar(1000)
DECLARE @RecordCount int,@P1 INT
DECLARE @Where VARCHAR(200)
IF @PageIndex >1 SET @PageIndex = (@PageIndex-1)*@PageSize +1
--IF @PageIndex = 1  SET @PageIndex =1

SET @Where = ''
IF ((@EnterpriseName IS NOT NULL) AND (RTRIM(LTRIM(@EnterpriseName))<>''))
BEGIN
  SET @Where = @Where +  ' AND (EnterpriseName LIKE ''%'+ @EnterpriseName + '%'' '
END
--IF ((LEN(@Where)>0) AND (LEFT(@Where,5)=' AND')) 
--BEGIN
--	SET @Where = @Where +  ' AND Location = '''+ @Region + ''''
--END
IF ((LEN(@Where)>0) AND (LEFT(@Where,5)=' AND')) 
BEGIN
	SET @Where = Right(@Where,LEN(@Where)-5)
END
SET @SQL = N'SELECT * FROM  RescueAgreement ORDER BY AgreementID DESC'
IF (LEN(@Where)>0)
BEGIN
  SET @SQL = 'SELECT * FROM  RescueAgreement WHERE ' + @Where + ' ORDER BY AgreementID DESC'
END
PRINT @SQL
EXEC sp_cursoropen @P1 OUTPUT, @SQL, @scrollopt = 1, @ccopt = 335873, @rowcount = @RecordCount OUTPUT 
IF (@P1 != 0)
BEGIN
  EXEC sp_cursorfetch @P1, 32,@PageIndex , @PageSize 
  EXEC sp_cursorclose @P1
END
select @RecordCount
return @@ERROR




